# -*- coding: utf-8 -*-
"""
Created on Tue Oct 15 14:08:16 2019

@author: XCL01
"""

def trim(s):
    l = len(s)
    while s[0: 1] == ' ' or s[-1] == ' ':#第一个是切片, 第二个是下标取
        if s[0] == ' ':
            s = s[1: ]
        if s[-1] == ' ':
            s = s[:-1]
    return s, l#当return放在while里面不会报错, 说明在s全为空的时候, 最后一次循环s变成空list, 切片的语法还是成立, while为0, 但是s[0]不存在, 报错
print(trim('     s     ')) #s为全空格才会出现15行注释情况
s = []
print(s[0:1] == [])